import React, { useState, useEffect } from 'react'
import { Button, message, Modal, Select } from 'antd';
import { AddPhysical } from './service'
const AddManagement = ({ GetData, isModalOpen, setIsModalOpen }) => {




    const [value, setValue] = useState([]);

    const [list, setList] = useState([])

    useEffect(() => {

        const arr = [];
        for (var i = 0; i < 50; i++) {
            arr.push({ label: `${i}区`, value: i.toString() });
        }
        setList(arr);
    }, [])

    const handleOk = () => {
        AddPhysical({ zone_number: value.join(',') }).then(res => {
            console.log(res)
            if (res.code == 0) {
                setIsModalOpen(false)
                message.success("添加成功")
                GetData()
            } else {
                message.error(res.msg)
            }
        })
    };




    return (
        <Modal
            title="添加物理区"
            closable={{ 'aria-label': 'Custom Close Button' }}
            visible={isModalOpen}
            onOk={handleOk}
            onCancel={() => setIsModalOpen(false)}
        >
            <div style={{ padding: 30 }}>
                <Select
                    options={list}
                    placeholder="请选择分区"
                    style={{ width: '100%' }}
                    value={value}
                    mode={"multiple"}
                    onChange={(value) => setValue(value)}
                />
            </div>
        </Modal>
    )
}

export default AddManagement